package com.z.ssmdemo.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SessionLoginHandler implements LoginHandler{
    @Override
    public void login(HttpServletRequest request, HttpServletResponse response,String username) {
        HttpSession session = request.getSession();
        session.setAttribute(USER_NAME_IN_SESSION,username);
    }

    @Override
    public boolean validateLogin(HttpServletRequest request) {
        Object attribute = request.getSession().getAttribute(USER_NAME_IN_SESSION);
        return attribute!=null;
    }

    @Override
    public void loginOut(HttpServletRequest request,String username) {
        HttpSession session = request.getSession();
        session.removeAttribute(USER_NAME_IN_SESSION);
        session.invalidate();
    }
}
